home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / p / portfoli / small_c / usr.man < prev    next >
Encoding:
Text File  |  1996-10-30  |  109.6 KB  |  3,180 lines

  1.           
  2.           
  3.           
  4.           
  5.           
  6.           
  7.           
  8.           
  9.           
  10.           
  11.           
  12.           
  13.                                                      ii
  14.                                                     iiii
  15.                                                      ii
  16.                          sss           cccc             
  17.                        ssssssss      cccccccc      iiiii
  18.                       sss    sss    ccc    ccc     iiiii
  19.                       sssss        ccc               iii
  20.                        sssss       ccc               iii
  21.                           sssss    ccc               iii
  22.                       sss    sss    ccc    ccc       iii
  23.                        ssssssss      cccccccc     iiiiiiiii
  24.                          ssss          cccc       iiiiiiiii
  25.           
  26.           
  27.                              Small C Interpreter
  28.                            Version 1.3 for MS-DOS
  29.                         Copyright (C) 1986 Bob Brodt
  30.           
  31.           
  32.                                 User's Manual
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.      Small C Interpreter                                      User's Manual
  62.  
  63.  
  64.      1. Introduction 
  65.  
  66.  
  67.                SCI is a "C" language interpreter loosely based on the 
  68.           language subset described in James Hendrix' "Small C" (see 
  69.           the Appendix "Differences From Small C").  It is a fully 
  70.           interactive interpreter (no compilation!) that includes a 
  71.           powerful full screen editor and a program trace facility.  
  72.           SCI was meant to be a stepping stone for the experienced 
  73.           BASIC programmer who is ready to move up to the exciting 
  74.           world of "C"!  
  75.  
  76.                SCI will run on any MS-DOS or PC-DOS computer that has 
  77.           a minimum of 64Kbytes of RAM, although 128Kbytes is 
  78.           recommended.  The available free memory (that portion of 
  79.           memory not used by the interpreter's code and data storage) 
  80.           is automatically divided among "user progam code", "variable 
  81.           table", "function table" and "stack" memory segments.  If 
  82.           necessary, the sizes of these segments may be changed at 
  83.           program startup, however their total may not exceed 
  84.           64Kbytes.  
  85.  
  86.                The integrated full-screen editor does require that the 
  87.           terminal emulation firmware in your computer be capable of 
  88.           recognizing certain terminal control character sequences 
  89.           (also known as "escape sequences") that perform cursor 
  90.           positioning and erasing of portions of the screen.  See the 
  91.           installation instructions in the "Editor" section of this 
  92.           manual.  
  93.  
  94.                The SCI interpreter is very similar to BASIC 
  95.           internally.  Each line of input is first scanned and 
  96.           "tokenized", a process in which language elements (numbers, 
  97.           variables, keywords, etc.) are converted to one-, two- or 
  98.           three-byte "tokens". These tokens are easier to handle by a 
  99.           computer than arbitrarily long character sequences.  Unlike 
  100.           BASIC however, SCI programs do not require line numbers - 
  101.           the program flow is directed by SCI purely through the 
  102.           structured programming constructs inherent in the "C" 
  103.           language.  This tokenization process allows SCI to run much 
  104.           faster than other interpreters that deal with the raw 
  105.           program text.  However, the "C" language was never designed 
  106.           to be an interpreted programming language like BASIC was, 
  107.           and the price that must be paid for this advantage is in the 
  108.           form of incompatibilities with standard "C" as defined by 
  109.           Kernighan and Ritchie.  
  110.  
  111.  
  112.      1.1. This Manual 
  113.  
  114.  
  115.                The documentation for SCI is found in the files 
  116.  
  117.  
  118.                                      - 1 -
  119.  
  120.  
  121.      Small C Interpreter                                      User's Manual
  122.  
  123.  
  124.           "USER.MAN" and "PROG.MAN" on the distribution disk.  It is 
  125.           divided into two sections: this, the "User's Manual" and the 
  126.           "Programmer's Manual".  
  127.  
  128.                If you already have a working knowledge of the C 
  129.           language, the User's Manual is all you need to help you get 
  130.           started quickly with SCI.  It contains a brief overview of 
  131.           SCI's features, a thorough description of the built-in 
  132.           editor with installation instructions, a list of "Library 
  133.           Functions" available to your program and a summary 
  134.           description of SCI's language subset.  The User's Manual 
  135.           also contains a brief description of the SCI symbolic 
  136.           debuger.  In the Appendix you will find quick reference 
  137.           sections that include a complete and terse definition of the 
  138.           language subset supported by SCI, a command summary for the 
  139.           SCI editor and program debuger, and an explanation of SCI 
  140.           error messages.  
  141.  
  142.                If you are just starting out in learning C, you will 
  143.           most likely want to read the overview section in the User's 
  144.           Manual and then go directly to the Programmer's Manual. The 
  145.           Programmer's Manual is a very introductory tutorial on the C 
  146.           language.  It is designed to be used along with SCI so that 
  147.           you can learn C by experimentation.  If you have a working 
  148.           knowledge of another programming language such as BASIC, you 
  149.           should have no trouble getting through the tutorial.  The 
  150.           Programmer's Manual also contains an introduction to program 
  151.           debuging techniques and full treatment of SCI's built-in 
  152.           debuger.  
  153.  
  154.  
  155.      1.2. Starting Out 
  156.  
  157.  
  158.                The files on the distribution diskette are: 
  159.  
  160.  
  161.                SCI.COM      - the interpreter program
  162.                SHELL.SCI    - the command shell, written in C
  163.                CALC.SCI     - a sample calculator program
  164.                USER.MAN     - User's Manual
  165.                PROG.MAN     - Programmer's Manual
  166.  
  167.  
  168.                As always, it is a good idea to make a working copy, 
  169.           and then store your distribution diskette in a safe place.  
  170.  
  171.                To start up SCI, make sure that SHELL.SCI resides on 
  172.           the current drive and then execute SCI.COM. The interpreter 
  173.           will then read and execute the C program it finds in 
  174.           SHELL.SCI. The program provided for  you in this file 
  175.           contains several items of information needed by the built in 
  176.  
  177.  
  178.                                      - 2 -
  179.  
  180.  
  181.      Small C Interpreter                                      User's Manual
  182.  
  183.  
  184.           editor, as well as some other useful functions.  The program 
  185.           in SHELL.SCI that gets executed by the interpreter is simply 
  186.           an endless loop that prompts you for a line of input from 
  187.           the console and hands it off to the interpreter for 
  188.           execution.  Actually this function could have been performed 
  189.           by the SCI program itself, but by placing this routine 
  190.           outside of the interpreter, you have the option of 
  191.           customizing the interpreter to suit your tastes.  See the 
  192.           section on The Shell in the Programmer's Manual for a 
  193.           detailed discussion of shell functions and customization.  
  194.  
  195.                You may also specify a different program file for SCI 
  196.           to execute on startup.  By typing the following operating 
  197.           system command line, for example: 
  198.  
  199.  
  200.                A>SCI B:STARTUP
  201.  
  202.           
  203.           the interpreter will search disk B: for a file called 
  204.           STARTUP and execute it in lieu of the default SHELL.SCI 
  205.           file.  Be aware, however, that the standard SHELL.SCI file 
  206.           contains many often-used operating system interface 
  207.           functions that must be copied over to your customized 
  208.           startup program if they are going to be used by that 
  209.           program.  See the section on Library Functions for a list of 
  210.           these functions.  
  211.  
  212.  
  213.      1.3. Memory Allocation 
  214.  
  215.  
  216.                The interpreter automatically divides up whatever free 
  217.           memory is available (after SCI is loaded) among four 
  218.           segments for use by your programs and data.  These segments 
  219.           are: the Program Code, Variable Table, Function Table and 
  220.           Stack. The Program Code segment contains the tokenized 
  221.           version of your program code.  The Variable Table contains 
  222.           information about all "active" variables.  Each function 
  223.           takes up exactly one entry in the Function Table. Finally, 
  224.           memory requirement for the Stack segment will grow and 
  225.           shrink as your program executes.  The stack is used only for 
  226.           temporary storage when expressions are evaluated.  
  227.  
  228.                If the interpreter complains about "out of memory", 
  229.           "too many variables", "too many functions" or "stack 
  230.           overflow", you may be able to circumvent the problem by 
  231.           telling SCI how much memory to assign to each of these four 
  232.           segments using the following MS-DOS command line options: 
  233.  
  234.  
  235.                -P nnnn - assign "nnnn" decimal bytes for program storage.
  236.  
  237.  
  238.                                      - 3 -
  239.  
  240.  
  241.      Small C Interpreter                                      User's Manual
  242.  
  243.  
  244.                -V nn   - allow space for a maximum of "nn" variables.
  245.                -F nn   - allow space for a maximum of "nn" functions.
  246.                -S nn   - set the stack size to "nn".
  247.  
  248.           
  249.           Thus, the command line: 
  250.  
  251.  
  252.                A>SCI -P 8000 -V 30 -F 80 -S 40
  253.  
  254.           
  255.           will set aside 8000 bytes for program storage, allow a 
  256.           maximum of 30 variables to be active at one time, allow a 
  257.           maximum of 80 function declarations and leave 40 stack 
  258.           entries.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.                                      - 4 -
  299.  
  300.  
  301.      Small C Interpreter                                      User's Manual
  302.  
  303.  
  304.      2. Using the Shell Program 
  305.  
  306.  
  307.                The stock version of the "shell program", found in the 
  308.           file SHELL.SCI on your distribution disk, simply displays a 
  309.           prompt on the console, reads a line of input, and attempts 
  310.           to execute the input line.  
  311.  
  312.                The shell maintains your program in its "program 
  313.           buffer" in memory.  When SCI first starts up, this buffer is 
  314.           empty so you must either create a program using SCI's editor 
  315.           or retrieve a previously created program from disk.  Before 
  316.           you exit from the shell, be sure to save your program on 
  317.           disk or the contents of the program buffer will be lost.  
  318.  
  319.                The standard shell recognizes four basic (pardon the 
  320.           pun) commands: "edit", "list", "load", "save" and "exit".  
  321.           These are functionally similar to the BASIC commands: 
  322.           "EDIT", "LIST", "LOAD", "SAVE" and "SYSTEM" respectively.  
  323.           Later as you become more familiar with the C language, you 
  324.           may wish to modify the shell program and add your own 
  325.           commands.  
  326.  
  327.                Anything else typed at the shell prompt is assumed to 
  328.           be a valid C statement and is handed off to the interpreter 
  329.           to be executed.  
  330.  
  331.  
  332.      2.1. Shell Commands 
  333.  
  334.  
  335.                Listed below are the shell commands.  In the 
  336.           descriptions below, anything enclosed in square brackets ([ 
  337.           and ]) is optional and anything enclosed in angle brackets 
  338.           (< and >) is a verbose description of the item required by 
  339.           the command.  
  340.  
  341.  
  342.                edit [<line#>]
  343.  
  344.  
  345.                The "edit" command invokes SCI's built-in screen editor 
  346.           (see the Editor section in the User's Manual for more 
  347.           details).  If the word "edit" is followed with a line number 
  348.           (in decimal), the editor will start up by displaying the 
  349.           page of the program that contains the line number, and move 
  350.           the cursor to that line.  If the requested line number is 
  351.           greater than the number of lines in the program buffer, the 
  352.           last page of the program is displayed.  
  353.  
  354.  
  355.                list [<from_line#>] [<to_line#>]
  356.  
  357.  
  358.                                      - 5 -
  359.  
  360.  
  361.      Small C Interpreter                                      User's Manual
  362.  
  363.  
  364.                This command lists the program currently in the program 
  365.           buffer on the screen in its entirety.  The listing may be 
  366.           stoped by pressing any key.  If the word "list" is followed 
  367.           by one number, the listing starts at that line number in the 
  368.           program.  If two numbers seperated by one or more spaces 
  369.           follow "list", the program listing will start with the first 
  370.           and end with the second line number in the program.  
  371.  
  372.  
  373.                load <filename>
  374.  
  375.  
  376.                The "load" command will load the program buffer from 
  377.           the given disk file name.  This command will destroy the 
  378.           current contents of the program buffer.  If the file name is 
  379.           omitted or the file is not found, SCI will display a "file 
  380.           I/O error" message and erase the program buffer.  
  381.  
  382.  
  383.                save <filename>
  384.  
  385.  
  386.                This will write the contents of the program buffer out 
  387.           to the disk file name.  If the file name is omitted or the 
  388.           file can't be created, SCI displays the "file I/O error" 
  389.           message.  This command does not alter the program buffer in 
  390.           memory.  
  391.  
  392.                Programs that are "save"d by SCI are ordinary text 
  393.           files, suitable for editing with your favourite text 
  394.           editor.  
  395.  
  396.  
  397.                exit
  398.  
  399.  
  400.                This command returns you to the MS-DOS command level.  
  401.           If anything was left in the shell's program buffer, it will 
  402.           be lost unless you have previously "save"ed it in a disk 
  403.           file.  
  404.  
  405.  
  406.      2.2. Running Your Program 
  407.  
  408.  
  409.                A C program is simply a collection of "functions" which 
  410.           (hopefully) all participate to successfully perform a single 
  411.                                                 ____                               task.  In "standard" C, every program must have one and only 
  412.           one function called "main".  This is where the program will 
  413.           start executing from.  In SCI's C, you need not have a 
  414.                                                         ___                      "main" function because SCI allows you to run any function 
  415.           in the program buffer by simply typing its name at the SCI 
  416.  
  417.  
  418.                                      - 6 -
  419.  
  420.  
  421.      Small C Interpreter                                      User's Manual
  422.  
  423.  
  424.           input prompt.  Suppose for example that our program buffer 
  425.           contained the following three functions: 
  426.  
  427.  
  428.                hex(n)
  429.                {
  430.                     putx(n);
  431.                }
  432.                oct(n)
  433.                {
  434.                     puto(n);
  435.                }
  436.                dec(n)
  437.                {
  438.                     putd(n);
  439.                }
  440.  
  441.  
  442.                We could execute any of these functions from the shell 
  443.           by simply typing, for example: 
  444.  
  445.  
  446.                > hex(256)
  447.  
  448.  
  449.                Note that we showed the shell's greater-than prompt (>) 
  450.           above for demonstration purposes only.  An SCI program is 
  451.           simply a collection of (not necessarily related) functions 
  452.           that can be run and debuged individually or in combination 
  453.           with other functions in the program buffer.  Thus if you 
  454.           plan to transport your program to a compiler, be sure to 
  455.           include a "main" function in the final product.  
  456.  
  457.  
  458.      2.3. Program Variables 
  459.  
  460.  
  461.                                ______                                             The interpreter always clears to zero all program 
  462.           variables before each shell statement is executed.  So if 
  463.           you initialize a variable from the shell, the same variable 
  464.           will be set to zero again before the very next C statement 
  465.           entered from the shell.  
  466.  
  467.                To illustrate, assume we have the following program in 
  468.           the program buffer: 
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.                                      - 7 -
  479.  
  480.  
  481.      Small C Interpreter                                      User's Manual
  482.  
  483.  
  484.                int sum;
  485.                
  486.                total(n)
  487.                {
  488.                     sum = sum + n;
  489.                }
  490.  
  491.  
  492.                This program uses the variable "sum" to keep a running 
  493.           total of numbers.  However, repeated calls to "total()" from 
  494.           the shell would be futile since the interpreter would always 
  495.           set "sum" to zero before each call.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.                                      - 8 -
  539.  
  540.  
  541.      Small C Interpreter                                      User's Manual
  542.  
  543.  
  544.      3. The Editor 
  545.  
  546.           
  547.  
  548.  
  549.      3.1. Introduction 
  550.  
  551.  
  552.                SCI's built in editor is screen oriented and is similar 
  553.           to the "standard" set by the popular WORDSTAR word 
  554.           processor.  The editor can be modified to work with almost 
  555.           any personal computer, by simply changing some variables in 
  556.           the shell file (SHELL.SCI).  This section will describe the 
  557.           installation procedure and give needed information for some 
  558.           of the more common personal computers.  
  559.  
  560.  
  561.      3.2. Keys 
  562.  
  563.  
  564.                The alphabetic character keys on your PC's keyboard are 
  565.           probably arranged in a typewriter keyboard pattern as shown 
  566.           below.  All editing commands (cursor motion, deleting, 
  567.           inserting, etc.) are control-key combinations (i.e. press 
  568.           and hold the CONTROL key and then press a letter key).  In 
  569.           this manual, we will use an up arrow, or circumflex (^) 
  570.           followed by a letter to indicate that the keystroke is a 
  571.           control-key combination.  In the keyboard diagram below, 
  572.           only the letter keys marked with an asterisk (*) are valid 
  573.           editing command control-keys.  What each of these 
  574.           control-keys does will be explained in detail in a later 
  575.           section.  
  576.  
  577.  
  578.                ----------------------------------------------
  579.                |                                            |
  580.                | -----------------------------------------  |
  581.                | | Q*| W*| E*| R*| T | Y*| U | I | O | P |  |
  582.                | -----------------------------------------  |
  583.                |   | A*| S*| D*| F*| G*| H*| J | K*| L*|    |
  584.                |   -------------------------------------    |
  585.                |      | Z*| X*| C*| V*| B*| N | M |         |
  586.                |      -----------------------------         |
  587.                |                                            |
  588.                ----------------------------------------------
  589.  
  590.  
  591.  
  592.      3.3. Screen Layout 
  593.  
  594.  
  595.                The editor uses all of the screen, except for the last 
  596.  
  597.  
  598.                                      - 9 -
  599.  
  600.  
  601.      Small C Interpreter                                      User's Manual
  602.  
  603.  
  604.           line, as a window into your program.  The last screen line 
  605.           is reserved for status and prompts.  The status line is 
  606.           divided into several fields as shown below: 
  607.  
  608.  
  609.                     L:nnnn C:nn  Insert  Mark:nnnn:nnnn
  610.                               |      |     |          |
  611.                               |      |     |     line numbers of start and
  612.                               |      |     |     end of a marked block
  613.                               |      |     |
  614.                               |      |   insert/replace mode indicator
  615.                               |      |
  616.                               |    current column number
  617.                               |
  618.                     current line number
  619.  
  620.  
  621.                The current line and column numbers are updated only if 
  622.           you haven't pressed a key within the last two seconds or 
  623.           so.  This lets you enter text or commands at typamatic 
  624.           speeds without slowing you down.  
  625.  
  626.                If an error should occur while you are editing your 
  627.           program, the status line will be erased and the error 
  628.           message displayed in its place.  You must then hit the 
  629.           <ESCAPE> key to acknowledge that you have seen the error 
  630.           message before you may continue editing.  Also, if the 
  631.           editor needs information from you (such as search strings, 
  632.           etc.) the appropriate prompts will appear in the status 
  633.           line.  
  634.  
  635.  
  636.      3.4. Configuration 
  637.  
  638.           
  639.  
  640.  
  641.      3.4.1. Screen Customization 
  642.  
  643.  
  644.                Modern computer terminals allow a programmer to 
  645.           manipulate the cursor and text displayed on the screen by 
  646.           means of specific character sequences sent to the terminal.  
  647.           These character sequences are known interchangably as 
  648.           "control codes" or "escape sequences".  
  649.  
  650.                Most personal computers have a program in ROM that 
  651.           emulates a specific terminal's control codes.  In the case 
  652.           of the IBM PC, this emulation program is a "device driver" 
  653.           program on disk (ANSI.SYS) and must be loaded into RAM when 
  654.           PC-DOS is first booted up (see your IBM PC-DOS manual for 
  655.           installation procedures of this device driver).  
  656.  
  657.  
  658.                                      - 10 -
  659.  
  660.  
  661.      Small C Interpreter                                      User's Manual
  662.  
  663.  
  664.                Your personal computer must have as a minimum, control 
  665.           codes to directly position the cursor anywhere on the 
  666.           screen, and either an "erase to end of line" or "erase to 
  667.           end of screen" control code.  The "erase to end of line" 
  668.           code must clear to spaces all character locations to the 
  669.           right of and including the cursor postion.  The "erase to 
  670.           end of screen" control code performs an "erase to end of 
  671.           line" function and then erases all lines below the current 
  672.           line to spaces.  If your terminal recognizes both of these 
  673.           erase control codes, use "erase to end of screen" in 
  674.           preference of "erase to end of line" because it is slightly 
  675.           faster.  
  676.  
  677.                If your computer does not provide these minimal control 
  678.           codes, SCI's built in editor can not be used.  In this case, 
  679.           you must resort to using your own text editor to write and 
  680.           modify your programs.  
  681.  
  682.                Your PC may also have control codes that perform more 
  683.           complicated functions such as inserting and deleting 
  684.           characters and lines.  These are not really necessary, 
  685.           however the editor is designed to take advantage of them if 
  686.           they exist.  You may need to do some experimenting with 
  687.           different combinations of escape sequence to achieve optimum 
  688.           speed performance from the editor.  
  689.  
  690.                A Terminal's control codes are made known to the SCI 
  691.           editor by way of system global program variables.  These 
  692.           program variables must be declared in your shell program 
  693.                                     ______                                     file (normally SHELL.SCI) before the "entry" keyword and 
  694.           must be assigned values in the mainline shell program (the 
  695.           function "main" in SHELL.SCI).  There is one variable for 
  696.           each control code.  If your PC does not have a particular 
  697.                                                            ___                control code, that corresponding variable should not be 
  698.           declared.  All variables must be declared as character 
  699.           pointers (i.e. char *) with the exception of "_nr", "_nc", 
  700.           "_ro", "_co" and _mhz, which are all char's.  The variable 
  701.           names and their corresponding control code function are 
  702.           listed below: 
  703.  
  704.  
  705.                 cp                                     _cp - cursor postion.  
  706.  
  707.                 el                                           _el - erase to end of line.  
  708.  
  709.                 es                                             _es - erase to end of screen.  
  710.  
  711.                 dc                                                                   _dc - delete the character under the cursor and move 
  712.                     left all characters to the right of the cursor.  
  713.  
  714.                 dl                                                                     _dl - delete the line the cursor is on and move up all 
  715.                     lines below it.  
  716.  
  717.  
  718.                                      - 11 -
  719.  
  720.  
  721.      Small C Interpreter                                      User's Manual
  722.  
  723.  
  724.                 ic                                                                _ic - insert a character before the one under the 
  725.                     cursor and move all characters to the right.  The 
  726.                            ____                                                            cursor must remain at the same position (i.e. at 
  727.                     the inserted character).  
  728.  
  729.                 il                                                                      _il - insert a line before the one the cursor is on and 
  730.                                                               ____                       move all lines below it down.  The cursor must 
  731.                     remain at the same position (i.e. on the newly 
  732.                     created blank line).  
  733.  
  734.                 bl                                                                 _bl - rings the console bell.  If this variable is 
  735.                     omitted, the standard ASCII BEL character will be 
  736.                     used (octal 007). You may also wish to flash the 
  737.                     screen momentarily to a different color if your PC 
  738.                     has color or reverse video capabilities.  
  739.  
  740.                 nr                                                                      _nr - number of rows (lines) on the screen.  Typically, 
  741.                     this is set to 24 (25 for the IBM PC).  
  742.  
  743.                 nc                                                                    _nc - number of columns, usually 80 but may be set to 
  744.                     40 on the IBM PC if you are in 40 column mode.  
  745.  
  746.                 ro                                                                  _ro - row offset.  The cursor position control code 
  747.                     assumes that the screen "home" position (top left 
  748.                     corner) starts at 0,0.  If this is not the case 
  749.                     for your PC you can add this offset, otherwise 
  750.                     omit this variable.  
  751.  
  752.                 co                                                   _co - column offset, same as above.  
  753.  
  754.                 mhz                                                              _mhz - CPU speed (in Megahertz) of your PC. This 
  755.                     variable controls the frequency at which the 
  756.                     editor's status line is updated.  
  757.  
  758.  
  759.                As mentioned earlier, the above variables are pointers 
  760.           to characters which should be assigned in your shell 
  761.           mainline program.  The assigned character strings may 
  762.           contain any of the data conversion codes recognized by the 
  763.           Library Function "printf()".  See the section on Sample 
  764.           Configurations (below) for examples.  
  765.  
  766.  
  767.      3.4.2. Keyboard Customization 
  768.  
  769.  
  770.                In addition, if any of the character pointer variables 
  771.           "_ka", "_kb", ... "_kz" are declared, the string pointed at 
  772.           by these variables is assumed to be the character sequence 
  773.           sent by a function key on your keyboard and will be 
  774.           recognized as an alias of the corresponding control-letter 
  775.           key combination.  
  776.  
  777.  
  778.                                      - 12 -
  779.  
  780.  
  781.      Small C Interpreter                                      User's Manual
  782.  
  783.  
  784.                For example, The VT-100 terminals send the character 
  785.           sequence: "ESCAPE [ A", "ESCAPE [ B", "ESCAPE [ C" and 
  786.           "ESCAPE [ D" for the up, down right and left arrow keys 
  787.           respectively.  So, instead of typing ^E, ^X, ^D and ^S to 
  788.           move the cursor around, we could declare the following 
  789.           variables: 
  790.  
  791.  
  792.                char *_ke, *_kx, *_kd, *_ks;
  793.                
  794.                _ke="\033[A";  # alias for ^E
  795.                _kx="\033[B";  # alias for ^X
  796.                _kd="\033[C";  # alias for ^D
  797.                _ks="\033[D";  # alias for ^S
  798.  
  799.           
  800.           and then use the VT-100's arrow function keys instead.  
  801.           Similarly, other keyboard function keys that transmit 
  802.           multiple characters or single control characters can be used 
  803.           to perform other editor functions.  
  804.  
  805.  
  806.      3.5. Sample Configurations 
  807.  
  808.  
  809.                This section contains the data declarations and 
  810.           assignments required by some of the more common PC's. The 
  811.           data declarations must be made before the "entry" keyword in 
  812.           SHELL.SCI, and the variable assignments must be done within 
  813.           the function immediately following the "entry" keyword.  For 
  814.           example, look at the configuration for the IBM PC in the 
  815.           distribution version of the SHELL.SCI file: 
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.                                      - 13 -
  839.  
  840.  
  841.      Small C Interpreter                                      User's Manual
  842.  
  843.  
  844.                #
  845.                # Small C Interpreter standard shell
  846.                #
  847.                char _nr, _nc, _ro, _co, *_cp, *_el;
  848.                     .
  849.                     .
  850.                     .
  851.                <Library Function declarations>
  852.                     .
  853.                     .
  854.                     .
  855.                entry
  856.                
  857.                char ln[80];
  858.                char pr[20000];
  859.                
  860.                main()
  861.                {
  862.                     .
  863.                     .
  864.                     .
  865.                     _nr=25;
  866.                     _nc=80;
  867.                     _ro=1;
  868.                     _co=1;
  869.                     _cp="\033[%d;%dH";
  870.                     _el="\033I";
  871.                
  872.                     while ( gets(ln) ) {
  873.                          .
  874.                          .
  875.                          .
  876.                     <main program loop>
  877.                          .
  878.                          .
  879.                          .
  880.                     }
  881.                }
  882.  
  883.  
  884.                Only a skeleton of the file is shown here so that you 
  885.           can see the relative locations of the editor variables' 
  886.           declarations and assignments.  Note that the declarations 
  887.                                 ______                                          must appear somewhere before the "entry" keyword, and the 
  888.           control character strings must be assignmed to these 
  889.                               ______                                           variables somewhere before the start of the main program 
  890.           loop.  
  891.  
  892.                In the sample configuration listings below, only the 
  893.           control character strings assignments are shown for 
  894.           brevity.  
  895.  
  896.  
  897.  
  898.                                      - 14 -
  899.  
  900.  
  901.      Small C Interpreter                                      User's Manual
  902.  
  903.  
  904.      3.5.1. IBM PC 
  905.  
  906.  
  907.                The IBM PC is probably the most common.  Note that the 
  908.           ANSI.SYS device driver must be installed for the SCI editor 
  909.           to work.  
  910.  
  911.  
  912.                _nr=25;            # the PC has 25 lines
  913.                _nc=80;            # of 80 columns each
  914.                _ro=_co=1;         # row/column numbering starts at 1
  915.                _cp="\033[%d;%dH"; # esc. seq. to position cursor
  916.                _el="\033I";       # esc. seq. to erase to end of line
  917.  
  918.  
  919.  
  920.      3.5.2. DEC Rainbow 100 
  921.  
  922.  
  923.                Digital Equipment Corp.s' Rainbow 100 recognizes a 
  924.           subset of the American National Standards Institute (ANSI) 
  925.           Control Sequences for Video Terminals (X3.64).  
  926.  
  927.  
  928.                _nr=24;
  929.                _nc=80;
  930.                _ro=1;
  931.                _co=1;
  932.                _cp="\033[%d;%dH"; # position cursor
  933.                _es="\033[J";   # erase to end of screen
  934.                _il="\033[M";   # insert a line
  935.                _ic="\033[4h%c\033[4l"; # insert a character
  936.                _dc="\033[P";   # delete a character
  937.                _bl="\033[?5h\033[?5l"; # bell flashes screen momentarily
  938.                _ke="\033[A";   # up-arrow key
  939.                _kx="\033[B";   # down-arrow key
  940.                _kd="\033[C";   # right-arrow key
  941.                _ks="\033[D";   # left-arrow key
  942.  
  943.  
  944.  
  945.      3.5.3. Heath H19 
  946.  
  947.  
  948.  
  949.                _nr=24;
  950.                _nc=80;
  951.                _ro=' ';
  952.                _co=' ';
  953.                _cp="\033Y%c%c"; # position cursor
  954.                _es="\033E";     # erase to end of screen
  955.  
  956.  
  957.  
  958.                                      - 15 -
  959.  
  960.  
  961.      Small C Interpreter                                      User's Manual
  962.  
  963.  
  964.      3.5.4. Zenith PC 
  965.  
  966.  
  967.  
  968.                _nr=24;
  969.                _nc=80;
  970.                _ro=' ';
  971.                _co=' ';
  972.                _cp="\033Y%c%c"; # position cursor
  973.                _es="\033E";     # erase to end of screen
  974.                _il="\033L";     # insert line
  975.                _dl="\033M";     # delete line
  976.  
  977.  
  978.  
  979.      3.5.5. Televideo 910 
  980.  
  981.  
  982.  
  983.                _nr=24;
  984.                _nc=80;
  985.                _ro=' ';
  986.                _co=' ';
  987.                _cp="\033=%c%c"; # position cursor
  988.                _el="\033T";     # erase to end of line
  989.  
  990.  
  991.  
  992.      3.6. Editor Commands 
  993.  
  994.  
  995.                Now that you have modified the file SHELL.SCI for your 
  996.           particular terminal, you are ready to use the editor.  This 
  997.           section describes all of the editor's commands in detail.  
  998.  
  999.                All of the editor commands are control-key combinations 
  1000.           (press and hold the CONTROL key while pressing a letter 
  1001.           key).  We will use an up arrow, or circumflex (^) followed 
  1002.           by a letter to indicate that the keystroke is a control-key 
  1003.           combination.  All other non-printing keys, such as the 
  1004.           <RETURN> and <BACKSPACE> keys, will be in UPPERCASE.  
  1005.  
  1006.  
  1007.      3.6.1. Exiting from the Editor 
  1008.  
  1009.  
  1010.                To exit the editor and return to the SCI shell, type a 
  1011.           ^Z.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.                                      - 16 -
  1019.  
  1020.  
  1021.      Small C Interpreter                                      User's Manual
  1022.  
  1023.  
  1024.      3.6.2. Cursor Movement 
  1025.  
  1026.  
  1027.  
  1028.                 E                                                                     ^E - move cursor up to previous line.  Screen scrolls 
  1029.                     down if cursor is at the top of the screen.  
  1030.  
  1031.                 X                                                                      ^X - move cursor down to next line.  Screen scrolls up 
  1032.                     if cursor is at the bottom of the screen.  
  1033.  
  1034.                 S                                                                     ^S - move cursor left one character position.  Cursor 
  1035.                     stops at left margin.  
  1036.  
  1037.                 D                                                                      ^D - move cursor right one character position.  Cursor 
  1038.                     stops at right margin.  
  1039.  
  1040.                 A                                                                   ^A - move cursor to beginning of previous "word". A 
  1041.                     "word" is defined as a continuous sequence of 
  1042.                     alphanumeric characters (i.e. letters and numbers 
  1043.                     - no punctuation).  
  1044.  
  1045.                 F                                                            ^F - move cursor to beginning of next word.  
  1046.  
  1047.                 R                                                                     ^R - move cursor one page (the height of the display) 
  1048.                     up towards the beginning of the program.  
  1049.  
  1050.                 C                                                                      ^C - move cursor one page down, towards the end of the 
  1051.                     program.  
  1052.  
  1053.                 RETURN  or  LINEFEED                                              <RETURN> or <LINEFEED> - if the status line shows 
  1054.                     "Replace" mode instead of "Insert", these keys 
  1055.                     will move the cursor down to the beginning of the 
  1056.                     next line.  
  1057.  
  1058.  
  1059.  
  1060.      3.6.3. Inserting and Deleting 
  1061.  
  1062.  
  1063.  
  1064.                 V                                                                     ^V - toggles Insert/Replace mode.  The status line at 
  1065.                     the bottom of the screen will indicate the current 
  1066.                     mode.  In Insert mode, any characters you type 
  1067.                     will be inserted before the current cursor 
  1068.                     position.  In Replace mode, old characters on a 
  1069.                     line are simply overwritten as you enter text.  
  1070.  
  1071.                 G                                                                       ^G - delete the character under the cursor.  The cursor 
  1072.                     stays in the same position.  
  1073.  
  1074.                 H                                                                       ^H - delete the character to the left of the cursor and 
  1075.                     move the cursor left one character.  
  1076.  
  1077.  
  1078.                                      - 17 -
  1079.  
  1080.  
  1081.      Small C Interpreter                                      User's Manual
  1082.  
  1083.  
  1084.                 Y                                                                      ^Y - delete the current line.  The cursor stays at the 
  1085.                     same line.  Note that the <EOF> mark at the end of 
  1086.                     the program can not be deleted.  
  1087.  
  1088.                 L                                                                    ^L - restore the original line if the cursor has not 
  1089.                     been moved off the line.  
  1090.  
  1091.                 RETURN  or  LINEFEED                                              <RETURN> or <LINEFEED> - if the status line shows 
  1092.                     "Insert" mode, these keys will insert a new blank 
  1093.                     line as follows: If the cursor is at line one, 
  1094.                     column one (top, left-most column) when a <RETURN> 
  1095.                     or <LINEFEED> is pressed, a new blank line is 
  1096.                              _____                                                          inserted above the current line; everywhere else, 
  1097.                                              _____                                          the new line is inserted below the current line.  
  1098.                     The cursor will rest on the newly inserted line 
  1099.                     and directly below the first non-space character 
  1100.                     in the previous line.  
  1101.  
  1102.  
  1103.  
  1104.      3.6.4. Extended Movement 
  1105.  
  1106.  
  1107.                The extended cursor motion commands require two 
  1108.           control-key keystrokes.  The first is always a ^Q (mnemonic 
  1109.           for Quickly move somewhere), and the second can be one of 
  1110.           the following: 
  1111.  
  1112.  
  1113.                 F                                                                     ^F - find a character sequence.  The cursor will move 
  1114.                     to the status line's prompt/error message field 
  1115.                     and you will be prompted for the character 
  1116.                     sequence to be searched for.  The search starts at 
  1117.                     the next character position to the right of the 
  1118.                     cursor on the current line.  When the character 
  1119.                     sequence is found, the cursor will rest on the 
  1120.                     first character of the sequence.  
  1121.  
  1122.                 A                                                                  ^A - find and replace character sequence.  You are 
  1123.                     prompted for the character sequence to be searched 
  1124.                     for, as above.  Next you are prompted for the 
  1125.                     character sequence that will replace the search 
  1126.                     string.  Finally, you have the option of 
  1127.                     performing the search/replace "globally" that is 
  1128.                     for every occurance in the program.  
  1129.  
  1130.                 L                                                                ^L - find next occurence of previously specified 
  1131.                     character sequence.  You will not be prompted for 
  1132.                     the sequence to be searched for.  
  1133.  
  1134.                 G                                                                      ^G - go to a specified line.  You are prompted for the 
  1135.                     line number to be displayed.  The cursor will rest 
  1136.  
  1137.  
  1138.                                      - 18 -
  1139.  
  1140.  
  1141.      Small C Interpreter                                      User's Manual
  1142.  
  1143.  
  1144.                     on the requested line usually in the center of the 
  1145.                     screen.  
  1146.  
  1147.                 S                                                               ^S - move cursor to beginning of current line.  
  1148.  
  1149.                 D                                                         ^D - move cursor to end of current line.  
  1150.  
  1151.                 E                                                   ^E - move cursor to top of screen.  
  1152.  
  1153.                 X                                                      ^X - move cursor to bottom of screen.  
  1154.  
  1155.                 R                                                           ^R - move cursor to first line of program.  
  1156.  
  1157.                 C                                                                     ^C - move cursor so that the last page of the program 
  1158.                     is displayed.  
  1159.  
  1160.                 B                                                                     ^B - move cursor to the beginning of a marked block.  
  1161.  
  1162.                 K                                                               ^K - move cursor to the end of a marked block.  
  1163.  
  1164.  
  1165.  
  1166.      3.6.5. Block and Miscellaneous Commands 
  1167.  
  1168.  
  1169.                These commands also require two control-key keystrokes 
  1170.           and include block marking, inserting/deleting and some "too 
  1171.           late to classify" commands.  
  1172.  
  1173.                Unlike the popular WORDSTAR word processor, SCI's 
  1174.           editor treats blocks as groups of lines instead of groups of 
  1175.           characters.  That is, a block starts at the beginning of a 
  1176.           line and includes all characters up to the end of a line.  
  1177.  
  1178.                The first of these two-keystroke block commands must be 
  1179.           a ^K (mnemonic for blocK (?)) and the second may be one of: 
  1180.  
  1181.  
  1182.                 B                                                                     ^B - mark beginning of a block.  The status line will 
  1183.                     show the line number of the beginning of the 
  1184.                     block.  
  1185.  
  1186.                 K                                                                     ^K - mark end of a block.  The status line is updated 
  1187.                     to show the end of the block.  
  1188.  
  1189.                 V                                                                       ^V - make a copy of a marked block and insert it before 
  1190.                     the current line.  You may not copy a block to 
  1191.                     itself: for example if the block starts at line 3 
  1192.                     and ends at line 10 and the cursor is currently 
  1193.                     resting on line 5, you will be severely beeped at 
  1194.                     by the editor.  
  1195.  
  1196.  
  1197.  
  1198.                                      - 19 -
  1199.  
  1200.  
  1201.      Small C Interpreter                                      User's Manual
  1202.  
  1203.  
  1204.                 Y                                              ^Y - delete the marked block.  
  1205.  
  1206.                 U                                                                    ^U - "unmark" the block.  The block markers (if any) 
  1207.                     are removed from the status line display.  
  1208.  
  1209.                 R                                                                  ^R - read a file from disk and insert its contents 
  1210.                     before the current line in the program.  You will 
  1211.                     be prompted for the file name.  
  1212.  
  1213.                 W                                                                     ^W - write the marked block to a disk file.  You will 
  1214.                     be prompted for the file name.  
  1215.  
  1216.  
  1217.  
  1218.      3.6.6. Tabs 
  1219.  
  1220.  
  1221.                Tabs are set at every 3 columns.  A ^I (or the <TAB> 
  1222.           key on your keyboard if you have one) will either insert 
  1223.           spaces or replace with spaces, depending on the current 
  1224.           Insert/Replace mode parameter, up to the next tab stop.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.                                      - 20 -
  1259.  
  1260.  
  1261.      Small C Interpreter                                      User's Manual
  1262.  
  1263.  
  1264.      4. Language Summary 
  1265.  
  1266.  
  1267.                Although SCI implements only a subset of the C 
  1268.           language, it is powerful enough to teach you the major 
  1269.           principles of C.  This section is meant as a reference for 
  1270.           the experienced C programmer that wants to get started with 
  1271.           SCI immediately.  
  1272.  
  1273.  
  1274.      4.1. Line Terminators 
  1275.  
  1276.  
  1277.                In standard C, a statement is typically terminated with 
  1278.           a semicolon (;). In SCI, all statements are terminated by 
  1279.           either the end of the line or by a semicolon, although the 
  1280.           semicolon is optional.  This means that an expression MUST 
  1281.           be completely contained on one line.  
  1282.  
  1283.  
  1284.      4.2. Comments 
  1285.  
  1286.  
  1287.                Comments start with a number symbol (#) and end at the 
  1288.           end of the current program line.  The standard C comment 
  1289.           delimiters, /* and */ are not recognized and will cause a 
  1290.           "syntax error" message.  
  1291.  
  1292.  
  1293.      4.3. Identifiers 
  1294.  
  1295.  
  1296.                Identifiers may be a maximum of 8 characters long, the 
  1297.           first character must be an uppercase or lowercase letter 
  1298.           ("a-z", "A-Z") or an underscore ("_"). The remaining 7 
  1299.           characters may include digits ("0-9").  
  1300.  
  1301.                The following are all examples of valid identifiers: 
  1302.  
  1303.  
  1304.                this_is_an_identifier
  1305.                _0123
  1306.                XYZ
  1307.  
  1308.  
  1309.  
  1310.      4.4. Keywords 
  1311.  
  1312.  
  1313.                The following words are reserved by SCI and may not be 
  1314.           used as variable names: 
  1315.  
  1316.  
  1317.  
  1318.                                      - 21 -
  1319.  
  1320.  
  1321.      Small C Interpreter                                      User's Manual
  1322.  
  1323.  
  1324.                break           entry           return
  1325.                char            for             switch
  1326.                case            if              sys
  1327.                else            int             while
  1328.  
  1329.  
  1330.                Most of these keywords are the standard language 
  1331.           elements and are described in any C text book.  
  1332.  
  1333.                The "entry" keyword is used to tell the interpreter 
  1334.           which function in the startup program (normally in the file 
  1335.           SHELL.SCI) is to be executed first after the program has 
  1336.           been loaded.  There may be only one "entry" within a 
  1337.           program.  Any functions or variables that were declared 
  1338.           before the "entry" keyword are considered "system globals" 
  1339.           and are globally known to all functions.  Among the system 
  1340.           globals in the standard shell file are the Library Functions 
  1341.           and the editor's control variables.  See the Programmer's 
  1342.           Manual for more information on system globals.  
  1343.  
  1344.                Functions and variables declared after the "entry" 
  1345.           keyword are hidden from user-written functions.  These 
  1346.           include the standard shell's control program (main) and its 
  1347.           associated variables.  
  1348.  
  1349.                The keyword "sys" is a user program interface to some 
  1350.           useful interpreter functions, such as the program editor.  
  1351.           These are described in the Library Functions section.  
  1352.  
  1353.  
  1354.      4.5. Constants 
  1355.  
  1356.           
  1357.  
  1358.  
  1359.      4.5.1. Numeric Constants 
  1360.  
  1361.  
  1362.                SCI supports decimal integer constants in the range 
  1363.           -32768 to 32767.  SCI also supports the standard C notation 
  1364.           for integer hexadecimal and octal notation.  
  1365.  
  1366.  
  1367.      4.5.2. Character Constants 
  1368.  
  1369.  
  1370.                A character constant must be surrounded by apostrophes 
  1371.           (') and may be one of the following: 
  1372.  
  1373.  
  1374.                1) a single ASCII alphanumeric or punctuation (i.e. 
  1375.                     printable) character 
  1376.  
  1377.  
  1378.                                      - 22 -
  1379.  
  1380.  
  1381.      Small C Interpreter                                      User's Manual
  1382.  
  1383.  
  1384.                2) a backslash (\) character followed by 3 octal digits 
  1385.                     which may be used to represent any 1 byte value 
  1386.  
  1387.                3) a backslash followed by one of the characters n, r, 
  1388.                     b or t which represent the <LINEFEED> (a.k.a. 
  1389.                     "newline"), <RETURN> (carriage return), 
  1390.                     <BACKSPACE> and <TAB> characters respectively 
  1391.  
  1392.  
  1393.                The following are examples of valid character 
  1394.           constants: 
  1395.  
  1396.  
  1397.                'A'     the ASCII character "A"
  1398.                '\177'  octal character
  1399.                '\n'    newline
  1400.                '\r'    carriage return
  1401.                '\b'    backspace
  1402.                '\t'    horizontal tab
  1403.                '\\'    the backslash character
  1404.                '\''    the apostrophe character
  1405.  
  1406.  
  1407.  
  1408.      4.5.3. String Constants 
  1409.  
  1410.  
  1411.                Strings may include any of the character constants 
  1412.           mentioned above, as for example: 
  1413.  
  1414.  
  1415.                "this is a string\007\n"
  1416.  
  1417.  
  1418.                Strings always include a null (zero) byte, marking the 
  1419.           end of the string.  A zero-length string may be written as 
  1420.           two consecutive quotes, thus: "" 
  1421.  
  1422.  
  1423.      4.6. Data Types 
  1424.  
  1425.  
  1426.                Only the "char" and "int" data types are supported.  
  1427.           Characters (char's) are 1 byte and integers (int's) 2 bytes 
  1428.           in length.  Both are treated as signed quantities.  Chars 
  1429.           may range in value from -128 to +127, ints range from -32768 
  1430.           to 32767.  
  1431.  
  1432.                SCI also supports pointers and arrays of both char and 
  1433.           int.  Pointers require 2 bytes of storage.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.                                      - 23 -
  1439.  
  1440.  
  1441.      Small C Interpreter                                      User's Manual
  1442.  
  1443.  
  1444.      4.7. Operators 
  1445.  
  1446.           
  1447.  
  1448.  
  1449.      4.7.1. Unary Operators 
  1450.  
  1451.  
  1452.                The following unary operators are supported, all are 
  1453.           evaluated from right to left: 
  1454.  
  1455.  
  1456.                +--------------------------------+
  1457.                | *     pointer                  |
  1458.                | &     address                  |
  1459.                | -     negation                 |
  1460.                | !     logical NOT              |
  1461.                | ~     one's complement         |
  1462.                | ++    pre- and post-increment  |
  1463.                | --    pre- and post-decrement  |
  1464.                +--------------------------------+
  1465.  
  1466.  
  1467.  
  1468.      4.7.2. Binary Operators 
  1469.  
  1470.  
  1471.                The following binary operators are supported, all are 
  1472.           evaluated from left to right.  The operators are listed from 
  1473.           highest to lowest precedence, by groups (enclosed in 
  1474.           boxes).  Each group of operators has the same precedence: 
  1475.  
  1476.  
  1477.                +--------------------------------+
  1478.                | *     multiplication           |
  1479.                | /     division                 |
  1480.                | %     modulo (remainder)       |
  1481.                +--------------------------------+
  1482.                +--------------------------------+
  1483.                | +     addition                 |
  1484.                | -     subtraction              |
  1485.                +--------------------------------+
  1486.                +--------------------------------+
  1487.                | <<    shift left               |
  1488.                | >>    shift right              |
  1489.                +--------------------------------+
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.                                      - 24 -
  1499.  
  1500.  
  1501.      Small C Interpreter                                      User's Manual
  1502.  
  1503.  
  1504.                +--------------------------------+
  1505.                | <     less than                |
  1506.                | >     greater than             |
  1507.                | <=    less than or equal to    |
  1508.                | >=    greater than or equal to |
  1509.                +--------------------------------+
  1510.                +--------------------------------+
  1511.                | ==    equal                    |
  1512.                | !=    not equal                |
  1513.                +--------------------------------+
  1514.                +--------------------------------+
  1515.                | &     bitwise AND              |
  1516.                +--------------------------------+
  1517.                +--------------------------------+
  1518.                | ^     bitwise exclusive OR     |
  1519.                +--------------------------------+
  1520.                +--------------------------------+
  1521.                | |     bitwise OR               |
  1522.                +--------------------------------+
  1523.                +--------------------------------+
  1524.                | &&    logical AND              |
  1525.                +--------------------------------+
  1526.                +--------------------------------+
  1527.                | ||    logical OR               |
  1528.                +--------------------------------+
  1529.  
  1530.  
  1531.  
  1532.      4.7.3. Assignment Operator 
  1533.  
  1534.  
  1535.                The assignment operator, "=", is evaluated from from 
  1536.           right to left and has lowest precedence of all operators.  
  1537.  
  1538.  
  1539.      4.7.4. Comma Operator 
  1540.  
  1541.  
  1542.                The Comma Operator (,) as used by SCI is not an 
  1543.           operator in the strict sense, but rather a function argument 
  1544.           and variable seperator.  Trying to use a comma anywhere 
  1545.           other than in function calls, or data declarations will 
  1546.           cause a "syntax error".  
  1547.  
  1548.  
  1549.      4.8. Program Control Flow Constructs 
  1550.  
  1551.  
  1552.                SCI supports the following programming constructs: 
  1553.  
  1554.  
  1555.                if ( <expression> ) <statement>
  1556.  
  1557.  
  1558.                                      - 25 -
  1559.  
  1560.  
  1561.      Small C Interpreter                                      User's Manual
  1562.  
  1563.  
  1564.                
  1565.                
  1566.                if ( <expression> ) <statement> else <statement>
  1567.                
  1568.                
  1569.                while ( <expression> ) <statement>
  1570.                
  1571.                
  1572.                for ( <expression> ; <expression> ; <expression> ) <statement>
  1573.                
  1574.                
  1575.                switch ( <expression> )
  1576.                {
  1577.                case <constant expression> : <statement>
  1578.                case <constant expression> : <statement>
  1579.                case <constant expression> : <statement>
  1580.                     .
  1581.                     .
  1582.                     .
  1583.                default : <statement>
  1584.                }
  1585.  
  1586.  
  1587.                All of these constructs require that the keyword ("if", 
  1588.           "while", etc.) and its associated ( <expression> ) all 
  1589.           appear on the same line of text.  The <statement> portion 
  1590.           may appear on the same or on a seperate line of text.  
  1591.  
  1592.                If a "default" statement is encountered inside a 
  1593.           "switch" before any <constant expression>'s (reading from 
  1594.           top to bottom) are found that match the switch <expression>, 
  1595.           then execution continues with the <statement> following the 
  1596.           "default" keyword.  This is in contrast to standard C that 
  1597.                                                       ___                   only executes the "default" statement after all "case 
  1598.           <constant expressions>" have been tested.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.                                      - 26 -
  1619.  
  1620.  
  1621.      Small C Interpreter                                      User's Manual
  1622.  
  1623.  
  1624.      5. The Library Functions 
  1625.  
  1626.  
  1627.                The "sys" keyword has been reserved by SCI as a means 
  1628.           of communicating between a user's program and the 
  1629.           interpreter.  It is treated exactly as a (pre-defined) 
  1630.           function that may be referenced by a user program.  
  1631.  
  1632.                A "sys" call may have several arguments, the number and 
  1633.           type of which depends upon the integer value of the last 
  1634.           (right-most) argument.  This right-most argument is called 
  1635.           the "sys number" and defines the actual function performed 
  1636.           by a "sys" call.  To make life easier and to provide a more 
  1637.           or less "standard" programming environment, higher- level 
  1638.           functions have been wrapped around these "sys" calls - these 
  1639.           are known as the "Library Functions" and may be found in the 
  1640.           standard command shell included in the distribution disk.  
  1641.           The "sys numbers" and their corresponding mnemonic name are 
  1642.           listed below.  
  1643.  
  1644.  
  1645.                0       version
  1646.                1       fputc
  1647.                2       fgetc
  1648.                3       fputs
  1649.                4       fgets
  1650.                5       sprintf
  1651.                6       sscanf
  1652.                7       fopen
  1653.                8       fread
  1654.                9       fwrite
  1655.                10      fclose
  1656.                11      fseek
  1657.                12      ftell
  1658.                13      bdos
  1659.                14      system
  1660.                15      exit
  1661.                16      stmt
  1662.                17      totok
  1663.                18      untok
  1664.                19      edit
  1665.                20      strcmp and strncmp
  1666.                21      strcpy and strncpy
  1667.                22      strlen
  1668.                23      malloc
  1669.                24      free
  1670.                25      load
  1671.                26      save
  1672.                27      list
  1673.                28      trace
  1674.                29      dirscan
  1675.  
  1676.  
  1677.  
  1678.                                      - 27 -
  1679.  
  1680.  
  1681.      Small C Interpreter                                      User's Manual
  1682.  
  1683.  
  1684.                The Library Functions are described below in more 
  1685.           detail.  Some of the "sys" functions do not have a 
  1686.           corresponding Library Function interface in SHELL.SCI, but 
  1687.           are described here anyway for completeness.  
  1688.  
  1689.  
  1690.      5.1. atoi 
  1691.  
  1692.           
  1693.           atoi( string ) 
  1694.           char *string; 
  1695.  
  1696.                Converts the string "str" containing the ASCII 
  1697.           representation of a decimal number to an integer.  The 
  1698.           string consits of optional leading spaces or tabs, an 
  1699.           optional plus or minus sign (+ or -) followed by one or more 
  1700.           decimal digits.  Returns the integer value of the ASCII 
  1701.           number string.  
  1702.  
  1703.                This function does not have a "sys" call number 
  1704.           equivalent but rather it uses the "sscanf" Library 
  1705.           Function.  
  1706.  
  1707.  
  1708.      5.2. bdos 
  1709.  
  1710.           
  1711.           bdos( cx, dx ) 
  1712.           int cx, dx; 
  1713.  
  1714.                Performs a call on the operating system's BDOS. The 
  1715.           arguments "cx" and "dx" will be copied to the machine's CX 
  1716.           and DX registers respectively before the BDOS call.  The 
  1717.           function returns the value of the CPU's AX register after 
  1718.           the call.  See your MS-DOS programmer's manual for more 
  1719.           details on BDOS calls.  
  1720.  
  1721.  
  1722.      5.3. dirscan 
  1723.  
  1724.           
  1725.           dirscan( afn, file ) 
  1726.           char *afn, file[20]; 
  1727.  
  1728.                This function will scan the disk directory for file 
  1729.           names that match the "ambiguous file name" given by the 
  1730.           string "afn". Ambiguous file names may contain "*" and "?"  
  1731.           wildcard characters as explained in your MS-DOS manual.  The 
  1732.           first file name found in the directory that matches will be 
  1733.           copied into the buffer at "file". To continue the directory 
  1734.           scan and search for the next matching file name, set "afn" 
  1735.           equal to zero.  Dirscan will return a 1 if a matching file 
  1736.  
  1737.  
  1738.                                      - 28 -
  1739.  
  1740.  
  1741.      Small C Interpreter                                      User's Manual
  1742.  
  1743.  
  1744.           name was found, zero if not.  
  1745.  
  1746.  
  1747.      5.4. edit 
  1748.  
  1749.           
  1750.           edit( line_num, program ) 
  1751.           int line_num 
  1752.           char *program 
  1753.  
  1754.                Invokes the built-in program editor, starting at the 
  1755.           line given by "line_num" on the tokenized program buffer 
  1756.           "program". Returns the new size of the program buffer after 
  1757.                                 ____ ________ __ ___ ________ __             the editing session.  This function is not included in 
  1758.           _____ ___             SHELL.SCI 
  1759.  
  1760.  
  1761.      5.5. exit 
  1762.  
  1763.           
  1764.           exit( value ) 
  1765.           int value 
  1766.  
  1767.                Causes the currently executing program to return 
  1768.           control to the operating system.  The number "value" is 
  1769.           returned to the operating system shell (usually COMMAND.COM 
  1770.           in MS-DOS).  
  1771.  
  1772.  
  1773.      5.6. fclose 
  1774.  
  1775.           
  1776.           fclose( channel ) 
  1777.           int channel; 
  1778.  
  1779.                Closes a disk file previously opened by the Library 
  1780.           Function "fopen". Returns zero if successful, -1 on error.  
  1781.  
  1782.  
  1783.      5.7. fgetc 
  1784.  
  1785.           
  1786.           fgetc( channel ) 
  1787.  
  1788.                Reads a single character from the given channel.  
  1789.           Returns the character read, or a -1 on error or end of 
  1790.           file.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.                                      - 29 -
  1799.  
  1800.  
  1801.      Small C Interpreter                                      User's Manual
  1802.  
  1803.  
  1804.      5.8. fgets 
  1805.  
  1806.           
  1807.           fgets( buffer, length, channel ) 
  1808.           char *buffer; 
  1809.           int length; 
  1810.           int channel; 
  1811.  
  1812.                Reads characters from the file associated with 
  1813.           "channel".  Characters are read from the file until either a 
  1814.           newline is encountered, length minus 1 characters have been 
  1815.           read, or an end of file is found.  Returns the address of 
  1816.           "buffer", or a zero on end of file.  
  1817.  
  1818.  
  1819.      5.9. fopen 
  1820.  
  1821.           
  1822.           fopen( file_name, mode ) 
  1823.           char *file_name, *mode; 
  1824.  
  1825.                Opens a disk file whose name is given by the string 
  1826.           "file_name".  The string "mode" determines how the file will 
  1827.           be opened: 
  1828.  
  1829.  
  1830.                 r                                                                  "r" - open for ASCII read.  The file MUST exist or 
  1831.                     fopen returns an error code.  
  1832.  
  1833.                 rw                                                               "rw" - open for ASCII read/write.  The file MUST 
  1834.                     exist.  
  1835.  
  1836.                 w                                                                      "w" - open for ASCII write.  If the file exists, it is 
  1837.                     first deleted.  
  1838.  
  1839.                 wr                                                                     "wr" - open for ASCII read/write.  If the file already 
  1840.                     exists, it is first deleted.  
  1841.  
  1842.                 a                                                                    "a" - open for ASCII write append.  If the file does 
  1843.                     not exist, it is created.  If it does exist, the 
  1844.                     file position pointer is positioned to the end of 
  1845.                     the file.  
  1846.  
  1847.                 ar                                                                    "ar" - open for ASCII read/write append.  If the file 
  1848.                     does not exist it is created.  If it DOES exist, 
  1849.                     it is opened and the file pointer positioned to 
  1850.                     the end of the file.  The file may then be read or 
  1851.                     written.  
  1852.  
  1853.  
  1854.                By appending a "b" to any of the modes above, the file 
  1855.           is opened in BINARY mode instead of ASCII.  
  1856.  
  1857.  
  1858.                                      - 30 -
  1859.  
  1860.  
  1861.      Small C Interpreter                                      User's Manual
  1862.  
  1863.  
  1864.                When a file is opened in ASCII mode, all <LINEFEED>s 
  1865.           ("\n") are converted to <RETURN> <LINEFEED> character pairs 
  1866.           when writing to the file.  Similarly, <RETURN> <LINEFEED> 
  1867.           pairs are converted to a single <LINEFEED> character on 
  1868.           input from the file.  
  1869.  
  1870.                In BINARY read/write mode, no such conversions are 
  1871.           performed.  
  1872.  
  1873.                Returns an integer value known as a "channel". The 
  1874.           special channels 0, 1 and 2 refer to the standard input, 
  1875.           standard output and standard error files, and are initially 
  1876.           set for I/O on the console.  The channel number must be used 
  1877.           in all Library calls that perform file I/O functions.  A 
  1878.           Minus one is returned if the file could not be opened.  
  1879.  
  1880.  
  1881.      5.10. fputc 
  1882.  
  1883.           
  1884.           fputc( c, channel ) 
  1885.           char c; 
  1886.           int channel; 
  1887.  
  1888.                Writes the character "c" to the specified file 
  1889.           channel.  Returns the character written, or a -1 on error.  
  1890.  
  1891.  
  1892.      5.11. fputs 
  1893.  
  1894.           
  1895.           fputs( string, channel ) 
  1896.           char *string; 
  1897.           int channel; 
  1898.  
  1899.                Writes the string to the specified file channel.  
  1900.           Returns zero, or a -1 on error.  
  1901.  
  1902.  
  1903.      5.12. fread 
  1904.  
  1905.           
  1906.           fread( buffer, length, channel ) 
  1907.           char *buffer; 
  1908.           int length; 
  1909.           int channel; 
  1910.  
  1911.                Reads a maximum of "length" bytes into memory at the 
  1912.           address pointed to by "buffer" from the open file, 
  1913.           "channel". If the file was opened in ASCII read or 
  1914.           read/write mode, "fread" only reads up to and including a 
  1915.           newline character.  If the file was opened in binary read 
  1916.  
  1917.  
  1918.                                      - 31 -
  1919.  
  1920.  
  1921.      Small C Interpreter                                      User's Manual
  1922.  
  1923.  
  1924.           mode, "length" number of characters are read if they are 
  1925.           available.  Note that "channel" must be the value returned 
  1926.           from a previous "fopen" Library Function call, and the file 
  1927.           must still be open.  Returns the number of characters that 
  1928.           were actually read, or 0 on EOF.  
  1929.  
  1930.  
  1931.      5.13. free 
  1932.  
  1933.           
  1934.           free( memory ) 
  1935.           char *memory 
  1936.  
  1937.                Returns to the memory pool the block of memory pointed 
  1938.           to by "memory" that was previously gotten from a "malloc" 
  1939.           Library Function call.  
  1940.  
  1941.  
  1942.      5.14. fseek and ftell 
  1943.  
  1944.           fseek( channel, offset, whence ) 
  1945.           int channel, offset, whence; 
  1946.           
  1947.           ftell( channel ) 
  1948.  
  1949.                These functions manipulate a file's position pointer.  
  1950.           The file position pointer determines where in the file the 
  1951.           next byte of data will be read from or written to.  The 
  1952.           argument "channel" is the file channel number; "offset" is a 
  1953.           byte position offset; "whence" determines how the "offset" 
  1954.           will be applied to the current file position pointer.  If 
  1955.           "whence" is zero, "fseek" will move the file position 
  1956.                                              _________                           pointer to "offset" bytes from the beginning of the file.  
  1957.           If "whence" is one, "fseek" will move the file position 
  1958.                                              _______ ________                     pointer to "offset" bytes from its current location, either 
  1959.           forward ("offset" is positive) or backward ("offset" is 
  1960.           negative) in the file If "whence" is two, "fseek" will move 
  1961.                                                                ___                the file position pointer to "offset" bytes from the end of 
  1962.           the file.  In this case, "offset" must be negative to move 
  1963.           the file position pointer towards the beginning of the 
  1964.           file.  
  1965.  
  1966.                Ftell simply returns the current file position.  
  1967.  
  1968.  
  1969.  
  1970.                                         NOTE                                           NOTE:
  1971.  
  1972.                Because SCI supports only integer variables, these 
  1973.                functions  may  only  be  used  on  files that are
  1974.                smaller than 32767 characters.  Standard C  allows
  1975.                you to manipulate much larger files.  
  1976.  
  1977.  
  1978.                                      - 32 -
  1979.  
  1980.  
  1981.      Small C Interpreter                                      User's Manual
  1982.  
  1983.  
  1984.      5.15. fwrite 
  1985.  
  1986.           
  1987.           fwrite( buffer, length, channel ) 
  1988.           char *buffer; 
  1989.           int length; 
  1990.           int channel; 
  1991.  
  1992.                Writes "length" number of characters from memory at the 
  1993.           address pointed to by "buffer" to the file associated with 
  1994.           "channel".  Note that "channel" must be the value returned 
  1995.           from a previous "fopen" Library Function call, and the file 
  1996.           must still be open.  Returns the number of characters 
  1997.           actually written if successful, or a -1 on error.  
  1998.  
  1999.  
  2000.      5.16. load 
  2001.  
  2002.           
  2003.           load( file, program ) 
  2004.           char *file, *program 
  2005.  
  2006.                Loads a program from the file whose name is pointed at 
  2007.           by "file", tokenizes the statements therein and places the 
  2008.           tokenized program at "program". Returns the size of the 
  2009.           resulting tokenized program.  If the file could not be 
  2010.                                                               ____             found, an error message is printed on the console.  This 
  2011.           ________ __ ___ ________ __ _____ ___             function is not included in SHELL.SCI 
  2012.  
  2013.  
  2014.      5.17. malloc 
  2015.  
  2016.           
  2017.           malloc( size ) 
  2018.           int size 
  2019.  
  2020.                Main memory allocator.  This function is responsible 
  2021.           for handing out (to programs) chunks of free memory to be 
  2022.           used by the program as it sees fit.  
  2023.  
  2024.  
  2025.                                     WARNING                                       WARNING:
  2026.  
  2027.                wreckless programs that write data beyond the size 
  2028.                of  the  allocated  chunk of memory will cause the
  2029.                allocator to loose its mind and dole out  "rotten"
  2030.                chunks of  memory.   This will almost surely cause
  2031.                SCI to crash and burn.  Returns  a  pointer  to  a
  2032.                block of  memory  "size"  bytes  long.  Be sure to
  2033.                de-allocate the block using the  Library  Function
  2034.                "free"  when  you're  done  with it, or it will be
  2035.                lost forever...    Also,  do  not  use  malloc  to
  2036.  
  2037.  
  2038.                                      - 33 -
  2039.  
  2040.  
  2041.      Small C Interpreter                                      User's Manual
  2042.  
  2043.  
  2044.                allocate  memory  for  SCI program buffers, or you
  2045.                will surely crash the system.  
  2046.  
  2047.  
  2048.  
  2049.      5.18. printf 
  2050.  
  2051.           
  2052.           printf( format, arg1, arg2, ... arg8 ) 
  2053.           char *format; 
  2054.           int arg1, arg2, ... arg8; 
  2055.  
  2056.                Prints a formatted string to the standard output file.  
  2057.           The characters in the string "format" are copied to the 
  2058.           standard output file.  If a percent character ("%") is 
  2059.           encountered in the format string, it is assumed to be a 
  2060.           conversion specification.  Each conversion specification 
  2061.           converts exactly one argument in the list "arg1", "arg2", 
  2062.           ... "arg8". Once an argument has been converted and output, 
  2063.           it is skipped over the next time a conversion specification 
  2064.           is encountered.  Therefore, you need just as many arguments 
  2065.           as you have conversion specifications (%-somethings).  
  2066.  
  2067.                The character(s) that follow a conversion specification 
  2068.           may be one or more of the following: 
  2069.  
  2070.  
  2071.                minus sign                                                             minus sign (-) - Indicates that output should be left 
  2072.                     justified instead of right justified.  
  2073.  
  2074.                zero fill character  0                                                 zero fill character (0) - The field will be padded on 
  2075.                     the left with zeros.  
  2076.  
  2077.                field width  number other than 0                                         field width (number other than 0) - This is the minimum 
  2078.                     # of characters output.  The field will be padded 
  2079.                     with zeros or blanks depending on the fill 
  2080.                     character (above).  
  2081.  
  2082.                precision    followed by a number                                 precision (. followed by a number) - For numeric 
  2083.                     fields, this is the # of decimal places to the 
  2084.                     right of the decimal point.  For string fields, at 
  2085.                     most that many characters of the string will be 
  2086.                     output.  
  2087.  
  2088.                conversion code  the letter d  u  x  o  b  s or c                       conversion code (the letter d, u, x, o, b, s or c) - A 
  2089.                     conversion code indicates the type of conversion 
  2090.                     that is to be done on the argument as follows: 
  2091.  
  2092.  
  2093.                          d - convert to a decimal (base 10) number
  2094.                          u - unsigned decimal number
  2095.                          x - hexadecimal (base 16) number
  2096.  
  2097.  
  2098.                                      - 34 -
  2099.  
  2100.  
  2101.      Small C Interpreter                                      User's Manual
  2102.  
  2103.  
  2104.                          o - octal (base 8) number
  2105.                          b - binary (base 2) number
  2106.                          s - string constant
  2107.                          c - single ASCII character
  2108.  
  2109.  
  2110.  
  2111.  
  2112.      5.19. save 
  2113.  
  2114.           
  2115.           save( file, program ) 
  2116.           char *file, *program 
  2117.  
  2118.                Saves a program in its tokenized form at "program" to 
  2119.           the file whose name is in the string "file". Returns the 
  2120.           number of bytes written to the file.  If the file could not 
  2121.           be created, an error message is printed on the console.  
  2122.           ____ ________ __ ___ ________ __ _____ ___             This function is not included in SHELL.SCI 
  2123.  
  2124.  
  2125.      5.20. scanf 
  2126.  
  2127.           
  2128.           scanf( format, arg1, arg2, ... arg8 ) 
  2129.           char *format 
  2130.           int arg1, arg2, ... arg8 
  2131.  
  2132.                Reads characters from the standard input file and 
  2133.           converts them using the conversion string "format" (same as 
  2134.           for Library Function "printf"). The arguments "arg1", 
  2135.                                      ________                                     "arg2", ... "arg8" must be pointers to the appropriate data 
  2136.           types.  
  2137.  
  2138.  
  2139.      5.21. sprintf 
  2140.  
  2141.           
  2142.           sprintf( buffer, format, arg1, arg2, ... arg8 ) 
  2143.           char *buffer, *format 
  2144.           int arg1, arg2, ... arg8 
  2145.  
  2146.                Performs formated conversion of the arguments, exactly 
  2147.           like the Library Function "printf()", but writes its output 
  2148.           to the "buffer" instead of the standard output file.  
  2149.  
  2150.  
  2151.      5.22. sscanf 
  2152.  
  2153.           
  2154.           sscanf( buffer, format, arg1, arg2, ... arg8 ) 
  2155.           char *buffer, *format 
  2156.  
  2157.  
  2158.                                      - 35 -
  2159.  
  2160.  
  2161.      Small C Interpreter                                      User's Manual
  2162.  
  2163.  
  2164.           int arg1, arg2, ... arg8 
  2165.  
  2166.                Performs formated input conversion of the arguments, 
  2167.           exactly like the Library Function "scanf()" but reads its 
  2168.           input from the "buffer" instead of the standard input file.  
  2169.  
  2170.  
  2171.      5.23. stmt 
  2172.  
  2173.           
  2174.           stmt( line, program ) 
  2175.           char *line, *program 
  2176.  
  2177.                Hands a C statement off to the interpreter for 
  2178.           execution.  The statement is in its untokenized form at 
  2179.           "line". The program, also in tokenized form, at "program" is 
  2180.           used by the interpreter to satisfy any global variable or 
  2181.                                                       ____ ________ __             function references made by the statement.  This function is 
  2182.           ___ ________ __ _____ ___             not included in SHELL.SCI 
  2183.  
  2184.  
  2185.      5.24. strcmp, strncmp 
  2186.  
  2187.           
  2188.           strcmp( string_1, string_2 ) 
  2189.           char *string_1, *string_2 
  2190.           
  2191.                or 
  2192.           
  2193.           strncmp( string_1, string_2, limit ) 
  2194.           char *string_1, *string_2 
  2195.           int limit 
  2196.  
  2197.                Compares (character-by-character) the two strings.  The 
  2198.           comparison stops when a zero is encountered in either of the 
  2199.           two strings.  "strncmp" does the same thing, but at most 
  2200.           "limit" number of bytes are compared.  Returns a 0 if the 
  2201.           two strings are identical, non- zero if they differ.  
  2202.  
  2203.  
  2204.      5.25. strcpy, strncpy 
  2205.  
  2206.           
  2207.           strcpy( string_1, string_2 ) 
  2208.           char *string_1, *string_2 
  2209.           
  2210.                or 
  2211.           
  2212.           strncpy( string_1, string_2, limit ) 
  2213.           char *string_1, *string_2 
  2214.           int limit 
  2215.  
  2216.  
  2217.  
  2218.                                      - 36 -
  2219.  
  2220.  
  2221.      Small C Interpreter                                      User's Manual
  2222.  
  2223.  
  2224.                Copies (character-by-character) "string_2" into 
  2225.           "string_1".  The functions stops after the first null 
  2226.           character is encountered in "string_2".  "strncpy" does the 
  2227.           same thing, but at most "limit" number of bytes are copied.  
  2228.           Returns nothing interesting.  
  2229.  
  2230.  
  2231.      5.26. strlen 
  2232.  
  2233.           
  2234.           strlen( string ) 
  2235.           char *string; 
  2236.  
  2237.                Returns the number of characters in the given string, 
  2238.           excluding the string's trailing zero byte.  
  2239.  
  2240.  
  2241.      5.27. system 
  2242.  
  2243.           
  2244.           system( command_string ) 
  2245.           char *command_string; 
  2246.  
  2247.                Executes the MS-DOS command interpreter (usually the 
  2248.           program in COMMAND.COM) and passes it the MS-DOS command 
  2249.           found in "command_string".  SCI remains suspended in memory 
  2250.           in its current state and will continue execution when the 
  2251.           command has completed.  The return value from "system" is 
  2252.           the completion status of the MS-DOS program, which may be 
  2253.           used to test for success or failure.  
  2254.  
  2255.  
  2256.      5.28. totok 
  2257.  
  2258.           
  2259.           totok( sourcebuf, tokenbuf ) 
  2260.           char *sourcebuf, *tokenbuf 
  2261.  
  2262.                Converts the C statement at "sourcebuf" to its 
  2263.           tokenized equivalent and places the result at "tokenbuf". 
  2264.                                              ____ ________ __ ___             Returns the length of "tokenbuf".  This function is not 
  2265.           ________ __ _____ ___             included in SHELL.SCI 
  2266.  
  2267.  
  2268.      5.29. trace 
  2269.  
  2270.           
  2271.           trace( on_off ) 
  2272.           int on_off; 
  2273.  
  2274.                Allows a program to enable or disable the SCI debuger.  
  2275.           If "on_off" is zero, the debuger is disabled, anything else 
  2276.  
  2277.  
  2278.                                      - 37 -
  2279.  
  2280.  
  2281.      Small C Interpreter                                      User's Manual
  2282.  
  2283.  
  2284.           enables it.  
  2285.  
  2286.  
  2287.      5.30. untok 
  2288.  
  2289.           
  2290.           untok( tokenbuf, sourcebuf ) 
  2291.           char *tokenbuf, *sourcebuf 
  2292.  
  2293.                Converts the tokenized statement at "tokenbuf" to its 
  2294.           printable form at "sourcebuf". Returns the length of 
  2295.           "tokenbuf" (not "sourcebuf"!). This function is the opposite 
  2296.                                     ____ ________ __ ___ ________ __             of the "totok" function.  This function is not included in 
  2297.           _____ ___             SHELL.SCI 
  2298.  
  2299.  
  2300.      5.31. version 
  2301.  
  2302.           
  2303.           version() 
  2304.  
  2305.                Returns a character string that contains SCI's program 
  2306.           identification and copyright notice, and the program's 
  2307.           current version number, namely the string: 
  2308.          Small C Interpreter V1.3 15Mar86 Copyright (C) 1986 Bob Brodt
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.  
  2319.  
  2320.  
  2321.  
  2322.  
  2323.  
  2324.  
  2325.  
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338.                                      - 38 -
  2339.  
  2340.  
  2341.      Small C Interpreter                                      User's Manual
  2342.  
  2343.  
  2344.      6. The Debuger 
  2345.  
  2346.  
  2347.                The Library Function "trace()" allows you to enable or 
  2348.           disable the SCI debuger.  When the debuger is enabled, you 
  2349.           can set and remove breakpoints, examine and modify program 
  2350.           variables and control the execution of your program.  
  2351.  
  2352.                When the debuger is enabled, it first displays each 
  2353.           line of the program on the console before it is executed, 
  2354.           followed by a question mark (?) prompt.  At this point, you 
  2355.           may either enter another valid C statement (to display the 
  2356.           contents of a variable for example), or enter one of the 
  2357.           following commands (NOTE: all of these commands must start 
  2358.           with a dot (.) immediately following the "?"  prompt to 
  2359.           distinguish them from a valid C statement): 
  2360.  
  2361.  
  2362.                b                                                               b# - sets a breakpoint at a given line in your 
  2363.                     program.  The "#" symbol represents the line 
  2364.                     number at which the program will be halted.  
  2365.  
  2366.                B                                                                  B - displays all breakpoints set in the program.  
  2367.  
  2368.                c                                                               c - continues program execution until the next 
  2369.                     breakpoint is encountered.  
  2370.  
  2371.                d                                                                    d# - deletes the breakpoint at line number "#". The 
  2372.                     breakpoint must have been previously set with a 
  2373.                     ".b" command.  
  2374.  
  2375.                D                                              D - deletes all breakpoints.  
  2376.  
  2377.                e                                                                   e# - lets you examine the program with the program 
  2378.                     editor.  Editor commands that would normally 
  2379.                     modify the program are disabled.  
  2380.  
  2381.                g                                                                       g - displays all of the program's global variables and 
  2382.                     their values.  If the variable is an array, its 
  2383.                     address is printed followed by the first 10 
  2384.                     elements of the array.  
  2385.  
  2386.                G                                                                     G - same as ".g" but also displays the first line of 
  2387.                     every function in the program along with its line 
  2388.                     number.  This is useful for locating a function in 
  2389.                     a long program.  
  2390.  
  2391.                q                                                                     q - quits program execution and returns to the shell 
  2392.                     program.  
  2393.  
  2394.                s                                                                       s# - steps through the program without displaying each 
  2395.                     line as it is executed.  The "#" is the number of 
  2396.  
  2397.  
  2398.                                      - 39 -
  2399.  
  2400.  
  2401.      Small C Interpreter                                      User's Manual
  2402.  
  2403.  
  2404.                     lines to be executed before control returns to the 
  2405.                     debuger.  
  2406.  
  2407.                t                                                                   t - displays the list of active functions with the 
  2408.                     current one at the top of the list.  This is handy 
  2409.                     for finding out "how did I get here?".  
  2410.  
  2411.                T                                                                   T - same as ".t" but also displays each function's 
  2412.                     local variables and their values.  
  2413.  
  2414.                 RETURN                                       <RETURN> - same as a ".s1".  
  2415.  
  2416.                 ESCAPE                                                                <ESCAPE> - is used to interrupt a program while it is 
  2417.                     running and enable the debuger.  
  2418.  
  2419.  
  2420.                If the SCI interpreter finds an error in your program, 
  2421.           it will automatically enable the debuger and halt the 
  2422.           program at the line where the error occurred.  This can be a 
  2423.           little confusing if you are already in the debuger and you 
  2424.           happen to make a mistake while typing a statement for the 
  2425.           debuger to execute, because the resulting error message and 
  2426.           the "?"  prompt will refer to the statement you just 
  2427.           entered.  If this happens, just hit a <RETURN> and you will 
  2428.           be returned to the program debug session.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.  
  2450.  
  2451.  
  2452.  
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.                                      - 40 -
  2459.  
  2460.  
  2461.      Small C Interpreter                                      User's Manual
  2462.  
  2463.  
  2464.      7. APPENDIX A: SCI Language Syntax 
  2465.  
  2466.  
  2467.                This appendix contains what is known as the 
  2468.           "Backus-Naur Form", or "BNF" of the SCI language.  Named 
  2469.           after its inventors, BNF is a very precise description of a 
  2470.           language and is useful as a reference for proper syntax.  
  2471.           The BNF of a language may at first be a little confusing, 
  2472.           but with practice it can be a very natural way of expressing 
  2473.           the syntax structure of any language.  
  2474.  
  2475.                The following rules apply to the BNF notation in this 
  2476.           appendix: 
  2477.  
  2478.  
  2479.                1) words that appear in UPPER CASE represent key 
  2480.                     elements of the language like the "IF" and "WHILE" 
  2481.                     keywords, or like the symbol for multiplication 
  2482.                     (*). These types of words are known as "TERMINALS" 
  2483.                     and, like atoms, they can not be broken into 
  2484.                     smaller parts.  
  2485.  
  2486.                2) Words in "lower case" represent what are called 
  2487.                     "non-terminals" and, as their name implies, they 
  2488.                     may consist of other smaller elements; either 
  2489.                     TERMINALS or non-terminals.  
  2490.  
  2491.                3) the word to be defined will appear on a line by 
  2492.                     itself, followed by a colon (:) followed by its 
  2493.                     definitions indented below it.  
  2494.  
  2495.                4) within a definition, language elements are seperated 
  2496.                     by a space.  
  2497.  
  2498.                5) depending upon its context, a language element may 
  2499.                     not appear at all and its definition is the 
  2500.                     special "empty" definition.  
  2501.  
  2502.                6) the SCI-style comment mark (#) is used only to 
  2503.                     clarify a definition and is not part of the 
  2504.                     definition 
  2505.  
  2506.  
  2507.                We have always been taught never to use a word we are 
  2508.           defining in its definition, that "recursive definitions" are 
  2509.           blasphemous!  However when defining language syntax it is 
  2510.           often desirable, indeed necessary, to use recursive 
  2511.           definitions.  Take for example the BNF description of a word 
  2512.           in the english language: a word may be one or more letters 
  2513.           strung together.  More formally, 
  2514.  
  2515.  
  2516.  
  2517.  
  2518.           APPENDIX                   - 41 -
  2519.  
  2520.  
  2521.      Small C Interpreter                                      User's Manual
  2522.  
  2523.  
  2524.                a "word": may be either:
  2525.                     1. a "letter", or
  2526.                     2. a "word" followed by a "letter"
  2527.  
  2528.  
  2529.                Here we can deduce definition number 2 because the 
  2530.           first letter of a word qualifies as a word itself, according 
  2531.           to our definition 1.  Even more formally, 
  2532.  
  2533.  
  2534.                word:
  2535.                     LETTER       # for example the word "a"
  2536.                     word LETTER  # for example the word "as"
  2537.  
  2538.  
  2539.                We have written "LETTER" in upper case to indicate that 
  2540.           a letter can not be broken down any further, i.e.  it is a 
  2541.           "TERMINAL". Similarly, "word" appears in lower case because 
  2542.           it can be broken down into smaller parts; it is a 
  2543.           "non-terminal".  
  2544.  
  2545.                Here then, is the BNF of the SCI language.  Assume that 
  2546.           you already know what the terminals LETTER (one of: a b 
  2547.           c...z, or A B C...Z, or _), NUMBER (one of: 0 1 2...9), 
  2548.           HEXDIGITS (0 1 2...9 A B...F) and OCTALDIGITS (0 1 2...7) 
  2549.           are.  
  2550.  
  2551.  
  2552.                id-list:           # identifier (variable) list
  2553.                     empty         # may be non-existent
  2554.                     id            # or a single identifier
  2555.                     id-list , id  # or two or more id's seperated by a comma
  2556.                
  2557.                id:                # an identifier (variable)
  2558.                     LETTER
  2559.                     id LETTER
  2560.                     id NUMBER
  2561.                
  2562.                hex-constant:      # hexadecimal constant
  2563.                     0 X HEXDIGITS
  2564.                
  2565.                oct-constant:      # octal constant
  2566.                     0 OCTALDIGITS
  2567.                
  2568.                dec-constant:      # decimal constant
  2569.                     NUMBER
  2570.                     constant NUMBER
  2571.                
  2572.                chr-constant:      # character constant
  2573.                     ' CHARACTER '
  2574.                
  2575.                str-constant:      # string constant
  2576.  
  2577.  
  2578.           APPENDIX                   - 42 -
  2579.  
  2580.  
  2581.      Small C Interpreter                                      User's Manual
  2582.  
  2583.  
  2584.                     " CHARACTER-LIST "
  2585.                
  2586.                constant:          # constants 'R' all of the above
  2587.                     dec-constant
  2588.                     hex-constant
  2589.                     oct-constant
  2590.                     chr-constant
  2591.                     str-constant
  2592.                
  2593.                expression-list:
  2594.                     empty
  2595.                     expression
  2596.                     expression-list , expression
  2597.                
  2598.                expression:
  2599.                     primary
  2600.                     * expression
  2601.                     & lvalue
  2602.                     ++ lvalue
  2603.                     -- lvalue
  2604.                     lvalue ++
  2605.                     lvalue --
  2606.                     - primary
  2607.                     + primary
  2608.                     ! expression
  2609.                     ~ expression
  2610.                     expression binop expression
  2611.                     lvalue = expression
  2612.                
  2613.                primary:
  2614.                     id
  2615.                     constant
  2616.                     string
  2617.                     ( expression )          # a parenthesized expression
  2618.                     id ( expression-list )  # a function call
  2619.                     id [ expression ]       # an array element
  2620.                
  2621.                lvalue:
  2622.                     id                      # a simple variable
  2623.                     id [ expression ]       # an array element
  2624.                     * expression            # a pointer expression
  2625.                
  2626.                binop:             # the binary operators:
  2627.                     *
  2628.                     /
  2629.                     %
  2630.                     +
  2631.                     -
  2632.                     <<
  2633.                     >>
  2634.                     <
  2635.                     <=
  2636.  
  2637.  
  2638.           APPENDIX                   - 43 -
  2639.  
  2640.  
  2641.      Small C Interpreter                                      User's Manual
  2642.  
  2643.  
  2644.                     >
  2645.                     >=
  2646.                     ==
  2647.                     !=
  2648.                     &
  2649.                     ^
  2650.                     |
  2651.                     &&
  2652.                     ||
  2653.                
  2654.                declaration-list:
  2655.                     empty
  2656.                     declaration
  2657.                     declaration-list declaration
  2658.                
  2659.                declaration:
  2660.                     type-spec declarator-list ;
  2661.                
  2662.                type-spec:
  2663.                     CHAR
  2664.                     INT
  2665.                
  2666.                declarator-list:
  2667.                     declarator
  2668.                     declarator-list , declarator
  2669.                
  2670.                declarator:
  2671.                     id
  2672.                     id [ constant ]
  2673.                     * id
  2674.                
  2675.                statement-list:
  2676.                     statement
  2677.                     statement-list statement
  2678.                
  2679.                compound-statement:
  2680.                     { declaration-list statement-list }
  2681.                
  2682.                statement:
  2683.                     ;                  # a no-op statement
  2684.                     compound-statement
  2685.                     expression ;
  2686.                     IF ( expression ) statement
  2687.                     IF ( expression ) statement ELSE statement
  2688.                     SWITCH ( expression ) statement
  2689.                     CASE constant : statement
  2690.                     DEFAULT : statement
  2691.                     BREAK ;
  2692.                     WHILE ( expression ) statement
  2693.                     FOR ( expression ; expression ; expression ) statement ;
  2694.                     RETURN ;
  2695.                     RETURN expression ;
  2696.  
  2697.  
  2698.           APPENDIX                   - 44 -
  2699.  
  2700.  
  2701.      Small C Interpreter                                      User's Manual
  2702.  
  2703.  
  2704.                
  2705.                function:
  2706.                     id ( id-list ) declaration-list compound-statement
  2707.                
  2708.                function-list:
  2709.                     empty
  2710.                     function
  2711.                     function-list function
  2712.                
  2713.                program:
  2714.                     empty
  2715.                     declaration-list
  2716.                     function-list
  2717.                     program declaration-list
  2718.                     program function-list
  2719.  
  2720.  
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.           APPENDIX                   - 45 -
  2759.  
  2760.  
  2761.      Small C Interpreter                                      User's Manual
  2762.  
  2763.  
  2764.      8. APPENDIX B: Editor Command Summary 
  2765.  
  2766.  
  2767.  
  2768.                 Z                         ^Z - exit 
  2769.  
  2770.                 E                              ^E - cursor up 
  2771.  
  2772.                 X                                ^X - cursor down 
  2773.  
  2774.                 S                                ^S - cursor left 
  2775.  
  2776.                 D                                 ^D - cursor right 
  2777.  
  2778.                 A                                                   ^A - cursor to end of previous word 
  2779.  
  2780.                 F                                                       ^F - cursor to beginning of next word.  
  2781.  
  2782.                 R                            ^R - page up 
  2783.  
  2784.                 C                              ^C - page down 
  2785.  
  2786.                 RETURN  or  LINEFEED                                             <RETURN> or <LINEFEED> - Replace Mode: cursor to 
  2787.                     beginning of next line Insert Mode: append blank 
  2788.                     line after current line 
  2789.  
  2790.                 V                                               ^V - toggle Insert/Replace Mode 
  2791.  
  2792.                 G                                                  ^G - delete character under cursor 
  2793.  
  2794.                 H or  BACKSPACE                                                        ^H or <BACKSPACE> - delete character to left of cursor 
  2795.  
  2796.                 Y                                ^Y - delete line 
  2797.  
  2798.                 L                                 ^L - restore line 
  2799.  
  2800.                 Q F                                ^Q^F - find string 
  2801.  
  2802.                 Q A                                            ^Q^A - find and replace string 
  2803.  
  2804.                 Q L                                                  ^Q^L - find next occurance of string 
  2805.  
  2806.                 Q G                               ^Q^G - go to line 
  2807.  
  2808.                 Q S                                                ^Q^S - cursor to beginning of line 
  2809.  
  2810.                 Q D                                          ^Q^D - cursor to end of line 
  2811.  
  2812.                 Q E                                            ^Q^E - cursor to top of screen 
  2813.  
  2814.                 Q X                                               ^Q^X - cursor to bottom of screen 
  2815.  
  2816.  
  2817.  
  2818.           APPENDIX                   - 46 -
  2819.  
  2820.  
  2821.      Small C Interpreter                                      User's Manual
  2822.  
  2823.  
  2824.                 Q R                                             ^Q^R - cursor to top of program 
  2825.  
  2826.                 Q C                                             ^Q^C - cursor to end of program 
  2827.  
  2828.                 Q B                                                 ^Q^B - cursor to beginning of block 
  2829.  
  2830.                 Q K                                           ^Q^K - cursor to end of block 
  2831.  
  2832.                 K B                                            ^K^B - mark beginning of block 
  2833.  
  2834.                 K K                                      ^K^K - mark end of block 
  2835.  
  2836.                 K V                                 ^K^V - insert block 
  2837.  
  2838.                 K Y                                 ^K^Y - delete block 
  2839.  
  2840.                 K U                                 ^K^U - unmark block 
  2841.  
  2842.                 K R                                        ^K^R - read from disk file 
  2843.  
  2844.                 K W                                             ^K^W - write block to disk file 
  2845.  
  2846.  
  2847.  
  2848.  
  2849.  
  2850.  
  2851.  
  2852.  
  2853.  
  2854.  
  2855.  
  2856.  
  2857.  
  2858.  
  2859.  
  2860.  
  2861.  
  2862.  
  2863.  
  2864.  
  2865.  
  2866.  
  2867.  
  2868.  
  2869.  
  2870.  
  2871.  
  2872.  
  2873.  
  2874.  
  2875.  
  2876.  
  2877.  
  2878.           APPENDIX                   - 47 -
  2879.  
  2880.  
  2881.      Small C Interpreter                                      User's Manual
  2882.  
  2883.  
  2884.      9. APPENDIX C: Debuger Command Summary 
  2885.  
  2886.           All debuger commands start with a dot (.) as the first 
  2887.           character in the command to distinguish them from valid C 
  2888.           statements.  
  2889.  
  2890.  
  2891.                b                                                           b# - set a breakpoint at line number "#".  
  2892.  
  2893.                B                                                  B - display all breakpoints set.  
  2894.  
  2895.                c                                                                    c - continue program execution to next breakpoint.  
  2896.  
  2897.                d                                                            d# - delete breakpoint at line number "#".  
  2898.  
  2899.                D                                             D - delete all breakpoints.  
  2900.  
  2901.                e                                                           e# - examine program with the SCI editor.  
  2902.  
  2903.                g                                                                  g - display global variables and their contents.  
  2904.  
  2905.                G                                                                    G - same as ".g" but also display the first line of 
  2906.                     every function in the program.  
  2907.  
  2908.                q                                               q - quit and return to shell.  
  2909.  
  2910.                s                                                                   s# - step "#" lines without displaying each line.  
  2911.  
  2912.                t                                                       t - display function call back trace.  
  2913.  
  2914.                T                                                                   T - same as ".t" but also displays each function's 
  2915.                     local variables and contents.  
  2916.  
  2917.                 RETURN                                      <RETURN> - same as ".s 1".  
  2918.  
  2919.                 ESCAPE                                                                 <ESCAPE> - interrupts an executing program and enables 
  2920.                     debuger.  
  2921.  
  2922.  
  2923.  
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.  
  2937.  
  2938.           APPENDIX                   - 48 -
  2939.  
  2940.  
  2941.      Small C Interpreter                                      User's Manual
  2942.  
  2943.  
  2944.      10. APPENDIX D: Differences From Small C 
  2945.  
  2946.  
  2947.                SCI supports the subset of the C language defined by J. 
  2948.           Hendrix' public domain "Small C" compiler, available for 
  2949.           many CP/M and MS-DOS machines.  There are, however, some 
  2950.           minor differences that have been dictated in part by the 
  2951.           fact that this is an interpreter.  These are: 
  2952.  
  2953.  
  2954.                1) Program source lines are limited to 80 characters, 
  2955.                     just to keep things simple.  The editor will 
  2956.                     complain if you try to create a line longer than 
  2957.                     80 characters.  
  2958.  
  2959.                2) There are no #define or #include statements, simply 
  2960.                     because there is no pre-processor!  
  2961.  
  2962.                3) Comments are introduced by the number symbol (#) and 
  2963.                     are terminated by the end of the line.  The "/*" 
  2964.                     and "*/" combinations will only be barfed at by 
  2965.                     SCI.  
  2966.  
  2967.                4) Statements in general are terminated by the end of a 
  2968.                     line - the semicolon required by the C language at 
  2969.                     the end of a statement is superfluous.  This 
  2970.                     restriction imposes that an expression be 
  2971.                     completely on one line (boooo, hissss!), however 
  2972.                     you no longer get penalized for forgeting a 
  2973.                     semicolon (hurray, yay!).  This also implies that 
  2974.                     string and character constants are terminated by 
  2975.                     the end of the line.  In fact, if you forget to 
  2976.                     add the terminating quote or apostrophe delimiter, 
  2977.                     SCI will append one for you.  
  2978.  
  2979.                5) Data variable initialization is not supported by 
  2980.                     SCI.  
  2981.  
  2982.                6) Local data variables declared inside a compound 
  2983.                     statement within a function may not have the same 
  2984.                     name as a previously declared local variable.  A 
  2985.                     "variable already declared" error will result.  
  2986.                     All other scope rules apply.  
  2987.  
  2988.                7) Pointer arithmetic is not smart enough to recognize 
  2989.                     data types so that pointers to integers are 
  2990.                     advanced to the next BYTE, not the next integer.  
  2991.                     For example, *(ip+1) will point to the least 
  2992.                     significant byte of the next integer (on an 8086 
  2993.                     machine), not the next word (booo, hisss!).  But, 
  2994.                     ip[1] and ++ip still point to the next integer 
  2995.                     (whew!).  Also, SCI allows does not restrict 
  2996.  
  2997.  
  2998.           APPENDIX                   - 49 -
  2999.  
  3000.  
  3001.      Small C Interpreter                                      User's Manual
  3002.  
  3003.  
  3004.                     pointer arithmetic to just addition and 
  3005.                     subtraction, like standard C does.  
  3006.  
  3007.                8) The logical AND and OR operators (&& and ||) 
  3008.                     evaluate both of their operands, unlike standard C 
  3009.                     which stops evaluation once the truth or falsehood 
  3010.                     of an expression is known.  
  3011.  
  3012.                9) The comma operator is recognized only when used in 
  3013.                     function calls and data declarations.  For 
  3014.                     instance, it would be illegal to say: while ( 
  3015.                     argv++, argc-- ); 
  3016.  
  3017.                10) The "default" statement inside a "switch" is 
  3018.                     executed as soon as it is encountered (when 
  3019.                     scanning from the top to the bottom of the 
  3020.                     "switch"). SCI is too lazy to do an exhaustive 
  3021.                     test of all "case"s before executing the 
  3022.                     "default", so be sure to place all "default"s as 
  3023.                     the last statement in the "switch".  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042.  
  3043.  
  3044.  
  3045.  
  3046.  
  3047.  
  3048.  
  3049.  
  3050.  
  3051.  
  3052.  
  3053.  
  3054.  
  3055.  
  3056.  
  3057.  
  3058.           APPENDIX                   - 50 -
  3059.  
  3060.  
  3061.      Small C Interpreter                                      User's Manual
  3062.  
  3063.  
  3064.      11. APPENDIX E: Error Messages 
  3065.  
  3066.  
  3067.                When SCI detects an error in your program, it will stop 
  3068.           execution, display an error message and then the line number 
  3069.           and program text of the offending line.  The SCI debuger is 
  3070.           then automatically enabled.  The possible error messages are 
  3071.           listed below: 
  3072.  
  3073.  
  3074.                no entry point                                                   no entry point - You forgot to specify an entry 
  3075.                     function with the "entry" keyword.  
  3076.  
  3077.                not enough table space                                                not enough table space - There was insufficient free 
  3078.                     memory available for the shell program, variable, 
  3079.                     function and stack segments.  Specify a smaller 
  3080.                     -P, -V, -F or -S value.  
  3081.  
  3082.                file I O error                                                         file I/O error - The specified program file could not 
  3083.                     be loaded, or SHELL.SCI does not exist on the 
  3084.                     default disk drive.  Or, the specified file could 
  3085.                     not be save on disk because of an operating system 
  3086.                     error.  
  3087.  
  3088.                missing                                                                 missing '}' - The interpreter wandered off the edge of 
  3089.                     your program because you forgot a closing brace.  
  3090.  
  3091.                missing operator                                              missing operator - The interpreter found two 
  3092.                     consecutive operands as for example the statement: 
  3093.                     var 3; 
  3094.  
  3095.                missing     or                                                  missing ')' or ']' - Mismatched left and right 
  3096.                     parentheses or brackets were detected.  
  3097.  
  3098.                not a pointer                                                          not a pointer - A simple "char" or "int" variable was 
  3099.                     used as an array or pointer.  
  3100.  
  3101.                syntax error                                                           syntax error - An error was detected in the structure 
  3102.                     of a statement or function.  
  3103.  
  3104.                lexical error                                                        lexical error - An illegal character was found in a 
  3105.                     statement.  
  3106.  
  3107.                need an lvalue                                                          need an lvalue - An attempt was made to assign a value 
  3108.                     to a constant or an array variable.  
  3109.  
  3110.                stack underflow                                                     stack underflow - Something is wrong!  Contact the 
  3111.                     author.  
  3112.  
  3113.                stack overflow                                                     stack overflow - The expression is too complex or 
  3114.                     function calls are nested too deeply.  Try 
  3115.                     specifying a larger -S value when starting up 
  3116.  
  3117.  
  3118.           APPENDIX                   - 51 -
  3119.  
  3120.  
  3121.      Small C Interpreter                                      User's Manual
  3122.  
  3123.  
  3124.                     SCI.  
  3125.  
  3126.                too many functions                                               too many functions - The interpreter ran out of 
  3127.                     Function Table space.  Try specifying a larger -F 
  3128.                     value when starting up SCI.  
  3129.  
  3130.                too many variables                                               too many variables - The interpreter ran out of 
  3131.                     Variable Table space.  Try specifying a larger -V 
  3132.                     value when starting up SCI.  
  3133.  
  3134.                out of memory                                                       out of memory - The interpreter ran out of Program 
  3135.                     space.  Try specifying a larger -P value when 
  3136.                     starting up SCI.  
  3137.  
  3138.                stmt outside of function                                             stmt outside of function - There is something wrong 
  3139.                     with the structure of your program.  Typically 
  3140.                     this results from a statement appearing outside of 
  3141.                     any function body.  
  3142.  
  3143.                missing                                                                  missing '{' - The left brace that introduces a function 
  3144.                     body was missing.  
  3145.  
  3146.                wrong   of arguments in sys call                                  wrong # of arguments in sys call - The number of 
  3147.                     arguments passed to a "sys" call is incorrect for 
  3148.                     the specified "sys" number.  
  3149.  
  3150.                undefined variable                                                     undefined variable - A variable has been used without 
  3151.                     ever having been declared.  
  3152.  
  3153.                variable already declared                                           variable already declared - An attempt was made to 
  3154.                     re-declare a variable name within the program or 
  3155.                     function.  
  3156.  
  3157.                interrupt                                                                interrupt - The program was interrupted by pressing the 
  3158.                     <ESCAPE> key.  
  3159.  
  3160.  
  3161.  
  3162.  
  3163.  
  3164.  
  3165.  
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.  
  3174.  
  3175.  
  3176.  
  3177.  
  3178.           APPENDIX                   - 52 -
  3179.  
  3180. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə